<?
//Data loading

$title='KWITANSI';
$title2='RECEIPT';
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = 'PT. MASAJI PRAYASA CARGO';

$page   = 'PAGE';

$DEFINE_FONT=0;
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = GridList ();
$pdf->GridTable($Result);
$pdf->Output();

function GridList () {
		    $DBConnection = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
                    $SQL = "SELECT * FROM ais_memorial WHERE nobkt='".GetParam("nobkt","")."' AND urut <> 999 ORDER BY urut";
                    return $DBConnection->dbc->get_results($SQL,ARRAY_A);
} 

function ReadHeader($nobkt) {
  global $DBConnection;
  $SQL = "SELECT *,DATE_FORMAT(tglbkt,'%d %M, %Y') as spell_date, jumlah  as TOTALPAID FROM ais_memorial WHERE nobkt='$nobkt' AND urut = 999  ";
  return $DBConnection->dbc->get_row($SQL);
}

class PDFReport extends PDF 
{

	function Header() 
	{
		global $title,$title2,$perush,$page,$DEFINE_FONT,$DBConnection;
		if ($DEFINE_FONT==0) {
			$this->AddFont('Arial','','arialn.php');
			$DEFINE_FONT=1;
		}

		 $Field = ReadHeader(GetParam("nobkt",""));
		 $DecimalPoint = ($Field->curr=="IDR")?0:2;
		 if (ereg("TB",GetParam("nobkt",""))) $type = "";
		 elseif (ereg("TK",GetParam("nobkt",""))) $type = "";
		 $this->spell_date = strtoupper($Field->spell_date);
		 list($this->year,$this->month,$this->day) = explode("-",$Field->tglbkt);
		 $this->curr = $Field->curr;
		 $this->TOTALPAID = $Field->TOTALPAID;

		 $this->SetFont('Arial','',8);
		 $this->Cell(45,3,"",0,1,'C');
		 $this->SetFont('Arial','',8);
		 $SQL = "SELECT * FROM tblprofile WHERE ktrasl='".GetOfficeID()."' ";
		 $Result = $DBConnection->dbc->get_row($SQL);
		 $this->Cell(45,3,"",0,1,'C');
		 $this->Cell(45,3,"",0,0,'C');
		 $this->SetFont('Arial','',16);
		 $this->Cell(90,9,$type,0,0,'C');
		 $this->SetFont('Arial','',5);
		 $this->Cell(45,9,'',0,1,'C');

		 $this->SetFont('Arial','',9);
		 $this->Cell(55,5,'',0,0,'R');
		 $this->Cell(55,5,$Field->uraian,0,0,'L');
		 $this->Cell(50,5,'',0,0,'R');
		 $this->Cell(20,5,GetParam("nobkt",""),0,1,'L');

		 $this->Cell(55,5,'',0,0,'R');
		 $this->Cell(55,5,$Field->debtur.', '.$Field->debnam,0,0,'L');
		 $this->Cell(50,5,'',0,0,'R');
		 $this->Cell(20,5,$this->day."/".$this->month."/".$this->year,0,1,'L');

		 $this->Cell(160,5,'',0,0,'R');
		 $this->Cell(20,5,$Field->curr,0,1,'L');

		 // Mulai header table...
	/*     
		 $this->SetFont('Arial','',9);
		 $this->Cell(10,5,'NO.',1,0,'C');
		 $this->Cell(60,5,'URAIAN',1,0,'C');
		 $this->Cell(25,5,'KODE',1,0,'C');
		 $this->Cell(40,5,'JUMLAH',1,0,'C');
		 $this->Cell(10,5,'DK',1,0,'C');
		 $this->Cell(10,5,'KTR',1,0,'C');
		 $this->Cell(10,5,'UU',1,0,'C');
		 $this->Cell(20,5,'REFERENSI',1,1,'C');
	*/

		 $this->SetFont('Arial','',9);
		 $this->Cell(10,5,'',0,0,'C');
		 $this->Cell(60,5,'',0,0,'C');
		 $this->Cell(25,5,'',0,0,'C');
		 $this->Cell(40,5,'',0,0,'C');
		 $this->Cell(10,5,'',0,0,'C');
		 $this->Cell(10,5,'',0,0,'C');
		 $this->Cell(10,5,'',0,0,'C');
		 $this->Cell(20,5,'',0,1,'C');

	}

	function GridTable($MyResult) 
	{
	    //Column widths
        global $DBConnection,$DecimalPoint;
	    $w=array(15,120,20,50);
	    
	    //Data
        $this->Cell(10,3,'','',0,'C');
        $this->Cell(60,3,'','',0,'C');
        $this->Cell(25,3,'','',0,'C');
        $this->Cell(40,3,'','',0,'C');
        $this->Cell(10,3,'','',0,'C');
        $this->Cell(10,3,'','',0,'C');
        $this->Cell(10,3,'','',0,'C');
        $this->Cell(20,3,'','',1,'C');
            
        if ($MyResult)
	    foreach($MyResult as $row)
	    {
            $Total = $Total + $row["jumlah"];
            $no++;
		    $this->Cell(10,3,$no,'',0,'C');
		    $this->Cell(60,3,$row["uraian"],'',0,'L');
		    $this->Cell(25,3,$row["skada"],'',0,'C');
		    $this->Cell(40,3,FormatNumber($row["jumlah"],$DecimalPoint),'',0,'R');
		    $this->Cell(10,3,$row["dk"],'',0,'C');
		    $this->Cell(10,3,$row["ktrasl"],'',0,'C');
		    $this->Cell(10,3,$row["kdact"],'',0,'C');
		    $this->Cell(20,3,$row["noref"],'',1,'L');
	    }

		$this->Cell(10,9,'','',0,'C');
		$this->Cell(60,9,'','',0,'C');
		$this->Cell(25,9,'','',0,'C');
		$this->Cell(40,9,'','',0,'C');
		$this->Cell(10,9,'','',0,'C');
		$this->Cell(10,9,'','',0,'C');
		$this->Cell(10,9,'','',0,'C');
		$this->Cell(20,9,'','',1,'C');
	}
	
	
	

	function Footer() {
		
			$cc = new intToRupiah;
			//$DBConnection->dbc->debug();
			$Field = ReadHeader(GetParam("nobkt",""));
			$cc->setTail("");
			$cc->setNumber($Field->TOTALPAID);
			$SpellNumber = ucfirst(strtoupper(trim($cc->currency)));
        
            $this->Cell(10,5,'','',0,'C');
            $this->Cell(60,5,'','',0,'L');
            $this->Cell(25,5,$Field->skada,'',0,'C');
            $this->Cell(40,5,FormatNumber($Field->TOTALPAID,$DecimalPoint),'',0,'R');
            $this->Cell(10,5,$Field->dk,'',0,'C');
            $this->Cell(10,5,$Field->ktrasl,'',0,'C');
            $this->Cell(10,5,$Field->untush,'',0,'C');
            $this->Cell(20,5,$Field->noref,'',1,'L');
        
            $this->Cell(10,5,'','',0,'C');
            $this->Cell(55,5,'','',0,'L');
            $this->Cell(120,5,'','',1,'L');
        
            //$this->Cell(180,5,'','LR',1,'L');
            
            $this->Cell(20,5,'Terbilang ','',0,'R');        
            $this->Cell(80,5,':   '.$SpellNumber,'',0,'L');
            $this->Cell(85,5,'','',1,'L');
            $this->Cell(185,5,'','',1,'L');
            
            $this->Cell(20,5,'','',0,'R');
            $this->Cell(75,5,''.$Field->debtur.'/'.$Field->princ,'',0,'L');
            $this->Cell(10,5,'',0,0,'R');
            $this->Cell(50,5,'','',0,'L');
            $this->Cell(30,5,'','',1,'L');
        
            $this->Cell(20,5,'','',0,'R');
            $this->Cell(75,5,'','',0,'L');
            $this->Cell(90,5,'','',1,'L');
        
            $this->Cell(20,5,'','',0,'R');
            $this->Cell(75,5,'','',0,'L');
            $this->Cell(10,5,'',0,0,'L');
            $this->Cell(10,5,'',0,0,'C');
            $this->Cell(10,5,'',0,0,'C');
            $this->Cell(20,5,'',0,0,'C');
            $this->Cell(10,5,'',0,0,'L');
            $this->Cell(30,5,'','',1,'L');
        
            $this->Cell(20,5,'','',0,'R');
            $this->Cell(75,5,''.$Field->noorder,'',0,'L');
            $this->Cell(10,5,'',0,0,'L');
            $this->Cell(10,5,'',0,0,'C');
            $this->Cell(10,5,'',0,0,'C');
            $this->Cell(20,5,'',0,0,'C');
            $this->Cell(10,5,'',0,0,'L');
            $this->Cell(30,5,''.$Field->depdat,'',1,'L');
        
            $this->Cell(185,5,'','',1,'L');
        
            // Tabel tanda tangan...
            $this->SetFont('Arial','',6);
            $this->Cell(60,5,'',0,0,'C');
            $this->Cell(65,5,'',0,0,'C');
            $this->Cell(60,5,'',0,1,'C');
        
        
            $this->Cell(15,5,'',0,0,'C');
            $this->Cell(45,5,'NAMA TTD 1',0,0,'C');
            $this->Cell(15,5,'',0,0,'C');
            $this->Cell(50,5,'NAMA TTD 2',0,0,'C');
            $this->Cell(15,5,'',0,0,'C');
            $this->Cell(45,5,'NAMA TTD 3',0,1,'C');
        
            $this->Cell(15,15,'',0,0,'C');
            $this->Cell(45,15,'',0,0,'C');
            $this->Cell(15,15,'',0,0,'C');
            $this->Cell(50,15,'',0,0,'C');
            $this->Cell(15,15,'',0,0,'C');
            $this->Cell(45,15,'',0,1,'C');
        
        
        
            //Position at 1.5 cm from bottom
            $this->SetY(-15);
            //Arial italic 8
            $this->SetFont('Arial','',8);
            //Page number
            $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
	}

}


?>
